/// with RUCA code
/// use "experimentdata_withRUCA.dta"




drop if check == 0

generate condimm = . 
replace condimm = 0 if rucarural == 0 & kltexp==0
replace condimm = 1 if rucarural == 0 & kltexp==1
replace condimm = 2 if rucarural == 0 & kltexp == 2
replace condimm = 3 if rucarural==0 & kltexp==3
replace condimm = 0 if rucarural == 4
replace condimm = 5 if rucarural == 1 & kltexp==0
replace condimm = 6 if rucarural == 1 & kltexp==1
replace condimm = 7 if rucarural == 1 & kltexp == 2
replace condimm = 8 if rucarural==1 & kltexp==3
replace condimm = 0 if rucarural == 9

graph bar (mean) expft_imm, over(kltexp) over(urb_sub_o) asyvars 


/// left-hand side of Figure 5
collapse (mean) meanimmexp= expft_imm (sd) sdftimm=expft_imm (count) n=expft_imm, by(kltexp rucarural condimm)
generate hiimmft = meanimmexp + invttail(n-1,0.025)*(sdftimm/sqrt(n))
generate loimmft = meanimmexp - invttail(n-1,0.025)*(sdftimm/sqrt(n))
graph twoway (bar meanimmexp kltexp) (rcap hiimmft loimmft kltexp), by(rucarural)
graph twoway (bar meanimmexp condimm if kltexp==0) (bar meanimmexp condimm if kltexp == 1) (bar meanimmexp condimm if kltexp==2) (bar meanimmexp condimm if kltexp==3) (rcap hiimmft loimmft condimm), legend (order(1 "Control" 2 "Economic Condition" 3 "Respect Condition" 4 "Majority-Minority Condition")) xlabel(0 "Non-Rural" 5 "Rural", noticks) xtitle("Respondent Partisanship") ytitle("Mean Undocumented Immigrant Feeling Therm. Score") scheme(s2gcolor)